#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
struct node
{
int data,h;
node* l;
node* r;
};
node* root=NULL;
int geth(node* p)//为了防止出现访问到NULL->h的情况,最好写一个函数出来
{
if(p==NULL)
return 0;
return p->h;
}
void update(node* p)//更新高度
{
p->h=max( geth(p->l),geth(p->r) )+1;
}
int bf(node* p)
{
return geth(p->l) - geth(p->r);
}
void L(node* &p)//L旋就是逆时针转。不用理会什么LR、RR之类的,那些是树型
{
node* temp;//必须要用temp保存即 将是新的根 的地址,因为要更新两个节点的h,不保存的话就找不到了
temp=p->r;
p->r=temp->l;
temp->l=p;
update(p);
update(temp);
p=temp;//之所以要引用的原因
}
void R(node* &p)//将上面函数
1066. Root of AVL Tree (25)--AVL树
最新推荐文章于 2022-10-22 11:51:34 发布